#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n;
string s,t;
int a,b;
int f[1145141];
void bfs()
{
	memset(f,0x3f,sizeof f);
	f[a]=0;
	queue<int>q;
	q.push(a);
	while(q.size())
	{
		int u=q.front();
		q.pop();
		for(int i=0;i<n;i++)
			for(int j=i;j<n;j++)
			{
				int suba=u,subb=u,subc=u;
				for(int k=i;k<=j;k++)
				{
					suba^=(1<<k);
					if(subb&(1<<k)) subb^=(1<<k);
					if(!(subc&(1<<k))) subc^=(1<<k);
				}
				if(f[suba]>1e9) f[suba]=f[u]+1,q.push(suba);
				if(f[subb]>1e9) f[subb]=f[u]+1,q.push(subb);
				if(f[subc]>1e9) f[subc]=f[u]+1,q.push(subc);
			}
	}
}
int main()
{
	freopen("hard.in","r",stdin);
	freopen("hard.out","w",stdout);
	n=read();cin>>s>>t;
	for(int i=0;i<s.size();i++) if(s[i]=='1') a+=(1<<i);
	for(int i=0;i<t.size();i++) if(t[i]=='1') b+=(1<<i);
	if(n<=18)
	{
		bfs();
		write(f[b]);
	}
	else
	{
		int cnta=0,cntb=0;
		t+='1';
		for(int i=0;i<t.size();i++)
		{
			if(t[i]=='0'&&t[i+1]!='0') ++cnta;
			if(t[i]=='1'&&t[i+1]!='1') ++cntb;
		}
		if(t[n-1]=='1') ++cntb;
		write(min(cnta,cntb+1)); 
	}
	return 0;
}
